#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <semaphore.h>

#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)

int main() {
	sem_t* sem = NULL;
	int value = 1;
	int ret = 0;

	sem = sem_open("sem", O_RDWR|O_CREAT, FILE_MODE, value);
	if (sem == SEM_FAILED) {
		printf("sem_open %s\n", strerror(errno));
		return -1;
	}

	sem_getvalue(sem, &ret);
	printf("%d\n", ret);
	sem_unlink("sem");

	return 0;
}
